home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Dashing Text ƒ / dashing text.c next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  4.2 KB  |  141 lines  |  [TEXT/KAHL]

  1. /*
  2.     dashing text.c 
  3.     
  4.     This file demonstrates dashing of text along a curve.
  5.     
  6.     NOTES:
  7.     • This file requires the following files to run correctly:
  8.         "graphics shell.c", "ColorLibrary.c", "FontLibrary.c",
  9.         "GraphicsDebugLibrary.c", "TransformLibrary.c".
  10.         
  11.     • This file prints the "best" in landscape mode.
  12.       
  13.  
  14.     Change History:
  15.  
  16.        4/96    bob        Updated #includes to support changed GX Library names.
  17.                     Updated the note regarding the files needed to run, and copyright date.
  18.  
  19.     ©1990 -1996  Apple Computer, Inc.
  20.     All rights reserved.
  21. */
  22.  
  23.  
  24. #include <events.h>
  25. #include <windows.h>
  26.  
  27. #include "FontLibrary.h"
  28. #include "GraphicsLibraries.h"
  29. #include <GXEnvironment.h>
  30. #include "graphics shell.h"
  31.  
  32. //
  33. //  Set up the title and size of the window 
  34. //
  35. Str255         gWindowTitle = "\p Dashing text";
  36. Rect         gWindowQDRect  = {50, 50, 240, 495};
  37.  
  38. //
  39. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  40. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  41. //    With gGraphicsHeapSize set to 105k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  42. //
  43. long        gGraphicsHeapSize = 105;
  44.  
  45. gxShape     gDashingShape;
  46.  
  47.  
  48. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  49.  
  50. void DoInitialization(aWindow)
  51. WindowPtr aWindow;
  52. {
  53.     gxCurve         curvepts = {{ff(10),ff(100)},{ff(150), -ff(55)},{ff(410),ff(150)}};
  54.     gxDashRecord    textDash;
  55.  
  56.      InitCommonColors();
  57.     
  58.     //  
  59.     //     Create the text shape that will be dashed
  60.      //  
  61.     textDash.dash = GXNewText(22,(unsigned char*)"QuickDraw™ GX is here!",  nil);
  62.     SetShapeCommonFont(textDash.dash, timesFont);
  63.     GXSetShapeTextSize(textDash.dash, ff(35));
  64.  
  65.     //  
  66.     // Set up the dash record.  Things to note: 
  67.     //        • scale should equal the text size. This will make sure that the text is dashed to the size of the curve
  68.     //        • If you want the textDash to be only used once on the curve, the advance must be larger than the curve's
  69.     //           length. You could use GXGetShapeLength (gDashingShape, ...); to determine the length of the curve and use this
  70.     //           value for advance.
  71.     //  
  72.     textDash.attributes = gxBreakDash | gxAutoAdvanceDash;
  73.     textDash.advance = ff(330);
  74.      textDash.phase = 0;
  75.     textDash.scale = ff(35);
  76.  
  77.     GXSetShapeType(textDash.dash, gxPathType);
  78.      
  79.     //  
  80.      //     Create the gxCurve to be dashed to.
  81.     //  
  82.       gDashingShape = GXNewCurve(&curvepts);
  83.       GXSetShapePen(gDashingShape, ff(35));
  84.     SetShapeCommonColor (gDashingShape, blue);
  85.     
  86.     //  
  87.     //     Add the textDash to the style of the gDashingShape. Since, we are adjusting the gxStyle of our shape and
  88.     //    this shape currently references the "default" style, GX graphics will make a copy of the style
  89.     //    and attach it to our shape.
  90.     //  
  91.     GXMoveShapeTo (gDashingShape, ff(30), ff(130));
  92.     GXSetShapeDash (gDashingShape, &textDash);
  93.     GXDisposeShape(textDash.dash);  
  94.   }
  95.  
  96.  
  97. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  98.  
  99. void DoDraw(aWindow)
  100. WindowPtr aWindow;
  101. {
  102.     GXDrawShape (gDashingShape);
  103. }
  104.  
  105.  
  106. /*------ DoDispose -------------------------------------------------------------------------------------*/
  107.  
  108. void DoDispose(aWindow)
  109. WindowPtr aWindow;
  110. {
  111.     //  
  112.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  113.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  114.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  115.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  116.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  117.     //  
  118.     GXDisposeShape(gDashingShape);  
  119.      GXDisposeShape(gWindowBoundsShape);  
  120.        DisposeCommonColors();
  121.        DisposeWindow(aWindow);
  122. }
  123.     
  124.  
  125.  
  126. /*------ DoClick ---------------------------------------------------------------------------------------*/
  127.  
  128. void DoClick( orgMouseLoc, theWindow )
  129. gxPoint        orgMouseLoc;
  130. WindowPtr     theWindow;
  131. {
  132. }
  133.  
  134.  
  135. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  136.  
  137. void DoIdle(aWindow)
  138. WindowPtr aWindow;
  139. {
  140. }
  141.